cmake_minimum_required(VERSION 3.5)

project(tool-box)

set(TOOL_BOX_DIR ${CMAKE_CURRENT_LIST_DIR})
set(TOP_DIR ${CMAKE_CURRENT_LIST_DIR}/../../)
set(TOOL_BOX_DIR ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

add_library(${PROJECT_NAME} SHARED)

execute_process(COMMAND bash ${TOOL_BOX_DIR}/translations/generate_translations_ts.sh
                WORKING_DIRECTORY ${TOOL_BOX_DIR})
execute_process(COMMAND bash ${TOOL_BOX_DIR}/translations/generate_translations_qm.sh
                WORKING_DIRECTORY ${TOOL_BOX_DIR})

target_compile_options(${PROJECT_NAME} PRIVATE -Wall -g -rdynamic)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

target_include_directories(${PROJECT_NAME} PRIVATE ${TOP_DIR}/interface)
target_include_directories(${PROJECT_NAME} PRIVATE ${TOP_DIR}/3rdparty/kyplugin)

find_package(Qt5 COMPONENTS REQUIRED Widgets DBus Svg)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets Qt5::DBus Qt5::Svg)

find_package(PkgConfig REQUIRED)

pkg_check_modules(KYSDK_KABASE kysdk-kabase)
target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDK_KABASE_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDK_KABASE_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDK_KABASE_LIBRARIES})

pkg_check_modules(KYSDK_UKENV kysdk-ukenv)
target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDK_UKENV_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDK_UKENV_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${KYSDK_UKENV_LIBRARIES})


set(SRCS "${TOOL_BOX_DIR}/connecter.cpp"
         "${TOOL_BOX_DIR}/plugininterface.cpp"
         "${TOOL_BOX_DIR}/toolboxwidget.cpp"
         "${TOOL_BOX_DIR}/appitem.cpp"
         "${TOP_DIR}/interface/kymanager_plugin.cpp"
         "${TOP_DIR}/src/utils.cpp"
         "${TOOL_BOX_DIR}/res.qrc")

target_include_directories(${PROJECT_NAME} PRIVATE ${TOOL_BOX_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${TOP_DIR}/src/)

target_sources(${PROJECT_NAME} PRIVATE ${SRCS})

file(GLOB TRANS
    "${TOOL_BOX_DIR}/translations/kylin-os-manager-tool-box_zh_CN.qm"
    "${TOOL_BOX_DIR}/translations/kylin-os-manager-tool-box_bo_CN.qm"
    "${TOOL_BOX_DIR}/translations/kylin-os-manager-tool-box_ug.qm"
    "${TOOL_BOX_DIR}/translations/kylin-os-manager-tool-box_kk.qm"
    "${TOOL_BOX_DIR}/translations/kylin-os-manager-tool-box_ky.qm")

install(TARGETS ${PROJECT_NAME} DESTINATION /opt/kylin-os-manager/plugins/)
install(FILES ${TRANS} DESTINATION  /usr/share/kylin-os-manager/translations/)
